package com.bwie.house.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.house.dao.AddressDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.house.entity.AddressEntity;
import com.bwie.house.service.AddressService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 
 *
 * @author wangguohai
 * @email 270901876@qq.com
 * @date 2022-04-21 20:35:04
 */
@RestController
@RequestMapping("house/address")
public class AddressController {
    @Autowired
    private AddressService addressService;
    @Autowired
    private AddressDao addressDao;

    @RequestMapping("list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = addressService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
    * @Author: 龍
    * @Description: 三级联动查询
    * @DateTime: 2022/4/29 19:02
    * @Params:
    * @Return
    */
    @RequestMapping("/listGXL/{id}")
    public R listGXL(@RequestParam Map<String, Object> params,
                  @PathVariable("id")String id){
        PageUtils page = addressService.queryPageGXL(params,id);

        return R.ok().put("page", page);
    }

    @RequestMapping("/citylist")
    public R citylist(@RequestParam Map<String, Object> params){
        List<AddressEntity> page = addressService.queryPage1(params);
        return R.ok().put("page", page);
    }

    /**
    * @author 張泽宇
    * @date 2022/4/22 17:23
    * @return
    */
    @GetMapping("/lists")
    public R lists(){
        List<AddressEntity> list = addressService.list();

        return R.ok().put("page", list);
    }

    @RequestMapping("/sheng")
    public R sheng(){
        QueryWrapper<AddressEntity> eq = new QueryWrapper<AddressEntity>().eq("parent_id", 0);
        List<AddressEntity> addressEntities = addressDao.selectList(eq);

        return R.ok().put("address", addressEntities);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{addressId}")
    public R info(@PathVariable("addressId") Integer addressId){
		AddressEntity address = addressService.getById(addressId);

        return R.ok().put("address", address);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AddressEntity address){
        addressService.save(address);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] addressIds){
		addressService.removeByIds(Arrays.asList(addressIds));

        return R.ok();
    }

}
